package com.hyj.ecp.clientservice.goods.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Service;

import com.ecp.goods.CustGoods;
import com.ecp.goods.GoodsQO;
import com.ecp.goods.GoodsTypeQO;
import com.hyj.ecp.backstage.sys.bean.qo.ConfigQO;
import com.hyj.ecp.clientservice.goods.service.IGoodsService;
import com.hyj.ecp.common.constant.SysConstant;
@Service
public class GoodsService implements IGoodsService {

	@Resource(name="sqlSession")
    public  SqlSessionTemplate sqlSession;

	@Override
	public List<GoodsTypeQO> queryGoodsType(GoodsTypeQO qo) {
		return sqlSession.selectList("com.ecp.client.goods.queryType", qo);
	}

	@Override
	public List<Map<String,Object>> queryGoods(GoodsQO qo) {
		if(qo.getPointPrice()>0){
			return sqlSession.selectList("com.ecp.client.goods.queryPointSaleGoods",qo);
		}
		return sqlSession.selectList("com.ecp.client.goods.queryGoods", qo);
	}

	@Override
	public int saveCustGoods(CustGoods qo) {
		//判断 当前物品是否已经收藏，如果收藏直接返回
		int a = sqlSession.selectOne("com.ecp.client.goods.queryCustGoodsNum", qo);
		if(a>0){
			return 1;
		}
		return sqlSession.insert("com.ecp.client.goods.saveCustGoods", qo);
	}

	@Override
	public Map<String, Object> queryGoodsInfo(GoodsQO qo) {
		return sqlSession.selectOne("com.ecp.client.goods.queryGoodsInfo", qo);
	}

	@Override
	public List<Map<String, Object>> queryCustGoods(CustGoods qo) {
		return sqlSession.selectList("com.ecp.client.goods.queryCustGoods", qo);
	}

	@Override
	public int deleteCustGoods(CustGoods qo) {
		return sqlSession.delete("com.ecp.client.goods.deleteCustGoods", qo);
	}

	@Override
	public String goodsActivityInfo(CustGoods qo) {
		ConfigQO cqo = new ConfigQO();
		if("gjp".equals(qo.getActivityType())){
			cqo.setType("goodssale"); 
			cqo.setKey("gjp");
			
		}else if("khfw".equals(qo.getActivityType())){
			cqo.setType("goodssale"); 
			cqo.setKey("khfw");
			
		}else if("cjwt".equals(qo.getActivityType())){
			cqo.setType("goodssale"); 
			cqo.setKey("cjwt");
			
		}else if("jgbh".equals(qo.getActivityType())){
			cqo.setType("goodssale"); 
			cqo.setKey("jgbh");
			
		}
		
		
		ConfigQO vo = sqlSession.selectOne("com.ecp.backstage.sys.login.queryConfig", cqo);
		return vo.getValue();
	}
	
	
}
